package com.smarthealthcare.system.service.impl;

import java.util.List;

import com.smarthealthcare.domain.Doctor;
import com.smarthealthcare.domain.Register;
import com.smarthealthcare.mapper.DoctorMapper;
import com.smarthealthcare.mapper.RegisterMapper;
import com.smarthealthcare.project.domain.Project;
import com.smarthealthcare.project.mapper.ProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smarthealthcare.system.mapper.PatientMapper;
import com.smarthealthcare.system.domain.Patient;
import com.smarthealthcare.system.service.IPatientService;

/**
 * 患者列表Service业务层处理
 *
 * @author YF
 * @date 2024-11-23
 */
@Service
public class PatientServiceImpl implements IPatientService {
    @Autowired
    private PatientMapper patientMapper;

    @Autowired
    private DoctorMapper doctorMapper;
    @Autowired
    private RegisterMapper registerMapper;
    @Autowired
    private ProjectMapper projectMapper;

    /**
     * 查询患者列表
     *
     * @param id 患者列表主键
     * @return 患者列表
     */
    @Override
    public Patient selectPatientById(Long id) {
        return patientMapper.selectPatientById(id);
    }

    /**
     * 查询患者列表列表
     *
     * @param patient 患者列表
     * @return 患者列表
     */
    @Override
    public List<Patient> selectPatientList(Patient patient) {
        List<Patient> list = patientMapper.selectPatientList(patient);
        for (Patient pa : list) {
            Doctor doctor = doctorMapper.selectDoctorById(pa.getDoctorId());
            Register register = registerMapper.selectRegisterById(pa.getRegisterId());
            Project project = projectMapper.selectProjectById(pa.getProjectId());
            pa.setDoctor(doctor);
            pa.setRegister(register);
            pa.setProject(project);
        }

        return list;
    }

    /**
     * 新增患者列表
     *
     * @param patient 患者列表
     * @return 结果
     */
    @Override
    public int insertPatient(Patient patient) {
        return patientMapper.insertPatient(patient);
    }

    /**
     * 修改患者列表
     *
     * @param patient 患者列表
     * @return 结果
     */
    @Override
    public int updatePatient(Patient patient) {
        return patientMapper.updatePatient(patient);
    }

    /**
     * 批量删除患者列表
     *
     * @param ids 需要删除的患者列表主键
     * @return 结果
     */
    @Override
    public int deletePatientByIds(Long[] ids) {
        return patientMapper.deletePatientByIds(ids);
    }

    /**
     * 删除患者列表信息
     *
     * @param id 患者列表主键
     * @return 结果
     */
    @Override
    public int deletePatientById(Long id) {
        return patientMapper.deletePatientById(id);
    }
}
